<template>
  <div class="hello">
    <mt-header fixed title="分类"></mt-header>

    <van-tabs v-model="active" class="nav" @click="onClick()">
      <van-tab
        :title="v.navigationName"
        v-for="v in navlist"
        :key="v.id"
      ></van-tab>
    </van-tabs>

     <van-search
      disabled
      @click.native="search()"
      class="search"
      placeholder="请输入搜索关键词"
    />
    <!-- 导航条详细内容 -->
    <div class="content">
      <div v-for="v in recommend" :key="v.id" class="tp" @click="play(v)">
        <div class="imgdiv">
          <img :src="v.albumPicUrl" alt="" />
        </div>

        <div>
          <p>歌曲：{{ v.musicName }}</p>
          <p>专辑：{{ v.albumName }}</p>
          <p>歌手：{{ v.artistName }}</p>
          <p>类别：{{ v.navigationName }}</p>
          <!-- <audio :src="v.musicMp3Url" controls></audio> -->
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import url from "../tools/url";
export default {
  name: "Fenlei",
  data() {
    return {
      active: 0,
      navlist: [],
      recommend: [],
    };
  },
  methods: {
     search() {
      this.$router.push("/search");
    },
    //播放音乐
    play(v){
        this.$store.commit("savemusic",v)
    },
    onClick() {
      console.log(this.active);
      var token = sessionStorage.getItem("token");
      var id = this.active + 1;
      if (id == 1) {
        this.axios.post(url.RECNAV,`token=${token}`).then((res) => {
          console.log;
          if (res.data.code == 200) {
            this.recommend = res.data.data;
          } else {
            this.$router.push("/Login").catch((e) => {});
          }
        });
      } else {
        var str = `token=${token}&id=${id}`;
        this.axios.post(url.NAVMUSIC, str).then((res) => {
          if (res.data.code == 200) {
            this.recommend = res.data.data;
          } else {
            this.$router.push("/Login").catch((e) => {});
          }
        });
      }
    },
  },
  mounted() {
    //请求导航条标题
    var token = sessionStorage.getItem("token");
    var str = `token=${token}`;
    this.axios.post(url.NAV, str).then((res) => {
      console.log(res);
      if (res.data.code == 200) {
        this.navlist = res.data.data;
      } else {
        this.$router.push("/Login").catch((e) => {});
      }
    });
    //获取推荐的内容
    this.axios.post(url.RECNAV, str).then((res) => {
      console.log;
      if (res.data.code == 200) {
        this.recommend = res.data.data;
      } else {
        this.$router.push("/Login").catch((e) => {});
      }
    });
  },
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.blank {
  clear: both;
  overflow: hidden;
  display: block;
  overflow: hidden;
}
.tp .imgdiv {
  width: 35%;
}
.tp {
  display: flex;

  margin-top: 10px;
  background: white;
}
.tp img {
  width: 100%;
}
.nav {
  top: 0px;
  position: fixed;
  z-index: 30;
}
.hello{
  margin-top: 50px;
}
</style>
